<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0"/>
<title>寻找1/20000000的你</title>

<script src="lib/easeljs-0.8.0.min.js"></script>
<script src="lib/tweenjs-0.6.0.min.js"></script>
<script src="lib/movieclip-0.8.0.min.js"></script>
<script src="lib/preloadjs-0.6.0.min.js"></script>
<script src="winsZhaoPin.js?r=20160330-1"></script>
<script>
    var _hmt = _hmt || [];
    (function() {
        var hm = document.createElement("script");
        hm.src = "//hm.baidu.com/hm.js?28eb9626d7631f37e627e1e8e4177f03";
        var s = document.getElementsByTagName("script")[0];
        s.parentNode.insertBefore(hm, s);
    })();
</script>


<script>
var canvas, stage, exportRoot;
var count = 0;//loading百分比
var tipsTxt;//提示文本
var images;//图片加载列表
var isWap;
var loadingMc;
var main,share_tips,oldmain;
//touch变量
var mainCurrentFrame=100;//当前所在帧数
var iniY=0;//初始y位置
var tempY=0;//临时y位置
var targetFrame=0;
var totalFrame=1000;
var stepFrame=100;
var iniTime=0;//初始时间
var nowTime=0;//当前时间

var audio_bg;
var reayAudio = false;
var firstPlay = true;
var currentP=1;

function init(){
    iniUiScale();
    initCjs();
    audio_bg = getEl('music_audio_bg');
    audio_bg.play();
    if (window.WeixinJSBridge) {
        WeixinJSBridge.invoke('getNetworkType', {}, function (e) {
            //alert('自动播放');
            if (firstPlay && audio_bg.currentTime == 0) {
                audio_bg.play();
                //home.btn_sound.visible=true;
                firstPlay = false;
            }
        });
    } else {
        document.addEventListener("WeixinJSBridgeReady", function () {
            WeixinJSBridge.invoke('getNetworkType', {}, function (e) {
                //alert('自动播放');
                if (firstPlay && audio_bg.currentTime == 0) {
                    audio_bg.play();
                    //home.btn_sound.visible=true;
                    firstPlay = false;
                }
            });
        }, false);

    }
}

//框架代码--------
function initCjs() {

    //audio_bg=getEl('music_audio_bg');
    //stageH = (640 / document.documentElement.clientWidth) * document.documentElement.clientHeight;
    canvas = getEl('mainCanvas');
    stage = new createjs.Stage(canvas);
    exportRoot = new lib.winsZhaoPin();
    stage.addChild(exportRoot);
    stage.update();
    stage.enableMouseOver();

    createjs.Ticker.setFPS(lib.properties.fps);
    createjs.Ticker.addEventListener('tick', stage);
    loading();
}

//loading
function loading() {
    loadingMc = new lib.LoadingMc();
    loadingMc.x = 0;
    exportRoot.addChild(loadingMc);

    images = images || {};
    var loader = new createjs.LoadQueue(false);
    //loader.installPlugin(createjs.Sound);
    loader.addEventListener('fileload', handleFileLoad);
    loader.addEventListener('complete', handleComplete);
    //loader.loadFile({src:"images/ShuangDan_atlas_.json", type:"spritesheet", id:"ShuangDan_atlas_"}, true);
    loader.loadManifest(lib.properties.manifest);
}
function handleFileLoad(evt) {
    if (evt.item.type == 'image') {
        images[evt.item.id] = evt.result;
    }
    count++;
    loadingMc.loadingText.text='loading '+(Math.floor(count/lib.properties.manifest.length*100))+'%';
}

function handleComplete(evt) {
    iniHome();
}

//初始化首页-------
function iniHome() {
    checkDevice();
    iniEvent();
    //清除loading
    exportRoot.removeChild(loadingMc);
    loadingMc = null;
    showPage(1);
    var btnsound=new lib.BtnSound();
    btnsound.x=570;
    btnsound.y=900;
    stage.addChild(btnsound);
    btnsound.addEventListener('click',soundClickHandle);
}
function iniEvent(){
    if (createjs.Touch.isSupported()) {
        createjs.Touch.enable(stage);
    }
}

function showPage(id){
    if(id==1){
        main=eval('new lib.Page'+id+'()');
        exportRoot.addChild(main);
        main.gotoAndPlay(1);
    }
    if(id>1 && id<=14){
        oldmain=main;
        createjs.Tween.get(oldmain).to({y:-1008}, 500).call(removePage);
        console.log('new lib.Page'+id+'()');
        main=eval('new lib.Page'+id+'()');
        main.y=1008;
        exportRoot.addChild(main);
        createjs.Tween.get(main).to({y:0}, 500).call(playPage);
    }
}
//上一页
function prePage(id){
    if(id>=1){
        oldmain=main;
        createjs.Tween.get(oldmain).to({y:1008}, 500).call(removePage);
        console.log('new lib.Page'+id+'()');
        main=eval('new lib.Page'+id+'()');
        main.y=-1008;
        exportRoot.addChild(main);
        createjs.Tween.get(main).to({y:0}, 500).call(playPage);
    }
}

function removePage(){
    exportRoot.removeChild(oldmain);
    oldmain=null;
}
function playPage(){
    main.gotoAndPlay(1);
}

//公用按钮按下事件
function btnMousedownHandle(evt){
    if(checkPointID(evt)){
        createjs.Tween.get(evt.currentTarget).to({scaleX: 0.9, scaleY: 0.9}, 100);
    }
}
function nextUpHandle(evt){
    if(checkPointID(evt)){
        createjs.Tween.get(evt.currentTarget).to({scaleX: 1, scaleY: 1}, 50);
        if(main){
            main.play();
        }
    }
}
//背景音乐开关
function soundClickHandle(evt){
    if(checkPointID(evt)){
        if(evt.currentTarget.currentFrame==0){
            evt.currentTarget.gotoAndStop(1);
            audio_bg.pause();
        }else{
            evt.currentTarget.gotoAndStop(0);
            audio_bg.play();
        }
    }
}
//上下滑动------------------------------------
function readyAddEvent(){
    stage.addEventListener("stagemousedown",stagemousedownHandle);
}
function stagemousedownHandle(event){
    event.preventDefault();

    iniY=event.stageY;
    tempY=event.stageY;
    iniTime=new Date().getTime();

    stage.addEventListener("stagemousemove",stagemousemoveHandle);
    stage.addEventListener("stagemouseup",stagemouseupHandle);
}


function stagemousemoveHandle(event){
    event.preventDefault();
    //console.log(main.currentFrame);
    if(event.stageY<tempY-10){
        //console.log("向上"+event.stageY);
        tempY=event.stageY;
    }
    if(event.stageY>tempY+10){
        //console.log("向下"+event.stageY);
        tempY=event.stageY;
    }
}

function stagemouseupHandle(event){
    event.preventDefault();

    nowTime=new Date().getTime();
    if(Math.abs(event.stageY-iniY)>200 ||(nowTime-iniTime)<500){
        if(event.stageY>iniY && (event.stageY>iniY+200 || (nowTime-iniTime)<500)){
            //判断用户是否向下移动了足够远
            if(currentP>1) {
                currentP--;
                console.log(currentP);
                prePage(currentP);
            }
        }
        if(event.stageY<iniY && (event.stageY<iniY-200 || (nowTime-iniTime)<500)){
            //判断用户是否向上移动了足够远
            if(currentP<14) {
                currentP++;
                console.log('currentP=' + currentP);
                showPage(currentP);
            }
        }
        stage.removeEventListener("stagemousedown",stagemousedownHandle);
    }else{

    }
    iniY=event.stageY;
    tempY=event.stageY;
    iniTime=new Date().getTime();

    stage.removeEventListener("stagemousemove",stagemousemoveHandle);
    stage.removeEventListener("stagemouseup",stagemouseupHandle);
}
//控制ui自适应
function iniUiScale() {
    var p = document.documentElement.clientWidth / 640;
    //getEl('share').style.zoom = p;
    //getEl('loading').style.zoom = p;
    //getEl('infoForm').style.zoom = p;
}
//----------终端检测------
function checkDevice() {
    if (!navigator.userAgent.match(/mobile/i)) {
        //alert("当前设备为pc");
        isWap = false;
    } else {
        //alert("当前设备为移动");
        isWap = true;
    }
}
function checkPointID(evt) {
    if (isWap) {
        if (evt.pointerID != -1) {
            return true;
        } else {
            return false;
        }
    } else {
        if (evt.pointerID == -1) {
            return true;
        } else {
            return false;
        }
    }
}
//获取dom
function getEl(id) {
    return document.getElementById(id);
}
//显示fps
function iniFps() {
    var fpsLabel = new createjs.Text("-- fps", "bold 18px Arial", "#ccc");
    stage.addChild(fpsLabel);
    fpsLabel.x = 10;
    fpsLabel.y = 20;
    fpsLabel.visible=true;
    fpsLabel.addEventListener('tick',fpsEnterFrameHandle);
    function fpsEnterFrameHandle(evt){
        fpsLabel.text = Math.round(createjs.Ticker.getMeasuredFPS()) + " fps";
    }
}

function checkPlatform() {
    if(/android/i.test(navigator.userAgent) && /MicroMessenger/i.test(navigator.userAgent)){
        return 'android-wx';
    }
    if(/(iPhone|iPad|iPod|iOS)/i.test(navigator.userAgent) && /MicroMessenger/i.test(navigator.userAgent)){
        return 'ios-wx';
    }
    return false;
}

</script>
<style>
    html, body {
        width: 100%;
        height: 100%;
        overflow: hidden;
        font-family: arial, "Hiragino Sans GB", "Microsoft Yahei", sans-serif;
    }

    body {
        margin: 0px;
        padding: 0px;
    }

    #mainCanvas {
        position: absolute;
        left: 0;
        top: 0;
        z-index: 2;
        width: 100%;
        height: 100%;
        display: inline-block;
    }

</style>
</head>

<body onload="init();" style="background-color:#BF676D">
<canvas id="mainCanvas" width="640" height="1050" style="background:#BF676D"></canvas>
<!-- 背景音乐显示-->
<div style="display: none">
    <audio id="music_audio_bg" preload="preload" loop="loop" style="display: none;">
        <source src="bgm.mp3" type="audio/mpeg">
    </audio>
</div>
<script type="text/javascript">
    document.body.ontouchmove=function(e){
        e.preventDefault();
    }
</script>
<script src="http://res.wx.qq.com/open/js/jweixin-1.0.0.js"></script>
<script src="http://hbweixin.twomi.cn/2016/accessToken/signPackage.php"></script>
<script>
    var shareLink = location.href;
    var shareImg = 'http://hbweixin.twomi.cn/2016/2016_winsZhaoPin/images/wxShare.jpg';
    var shareTitle = '寻找1/20000000的你';
    var shareDesc = '汪氏整合营销传播集团找你';
    //console.log('appId='+signPackage.appId);
    //console.log('timestamp='+signPackage.timestamp);
    //console.log('nonceStr='+signPackage.nonceStr);
    //console.log('url='+signPackage.url);
    //console.log('signature='+signPackage.signature);
    // 注意：所有的JS接口只能在公众号绑定的域名下调用，公众号开发者需要先登录微信公众平台进入“公众号设置”的“功能设置”里填写“JS接口安全域名”。
    // 如果发现在 Android 不能分享自定义内容，请到官网下载最新的包覆盖安装，Android 自定义分享接口需升级至 6.0.2.58 版本及以上。
    // 完整 JS-SDK 文档地址：http://mp.weixin.qq.com/wiki/7/aaa137b55fb2e0456bf8dd9148dd613f.html
    function iniWx(){
        wx.config({
            debug: false,
            appId: signPackage.appId,
            timestamp: parseInt(signPackage.timestamp),
            nonceStr: signPackage.nonceStr,
            signature: signPackage.signature,
            jsApiList: [
                'checkJsApi',
                'onMenuShareTimeline',
                'onMenuShareAppMessage',
                'onMenuShareQQ',
                'onMenuShareWeibo'
            ]
        });
        //config接口处理成功后
        wx.ready(function () {
            // 1 判断当前版本是否支持指定 JS 接口，支持批量判断
            wx.checkJsApi({
                jsApiList: [
                    'getNetworkType',
                    'onMenuShareTimeline',
                    'onMenuShareAppMessage',
                    'onMenuShareQQ',
                    'onMenuShareWeibo'
                ],
                success: function (res) {
                    //alert(JSON.stringify(res));
                    //网络+分享
                    checkResult = eval('(' + JSON.stringify(res) + ')');
                    checkResult = checkResult.checkResult;
                    if (checkResult.getNetworkType) {
                        getNetworkType();
                    }
                    if (checkResult.onMenuShareTimeline) {
                        onMenuShareTimeline();
                    }
                    if (checkResult.onMenuShareAppMessage) {
                        onMenuShareAppMessage();
                    }
                    if (checkResult.onMenuShareQQ) {
                        onMenuShareQQ();
                    }
                    if (checkResult.onMenuShareWeibo) {
                        onMenuShareWeibo();
                    }
                }
            });
        });
        //错误
        wx.error(function (res) {
            alert(res.errMsg);
        });
    }


    //------------------------------以下为常规接口-------------------------
    //配置检测网络接口
    function getNetworkType() {
        wx.getNetworkType({
            success: function (res) {
                console.log(res.networkType);
            },
            fail: function (res) {
                console.log(JSON.stringify(res));
            }
        });
    }
    //注册获取“发送给朋友”状态事件
    function onMenuShareAppMessage() {
        wx.onMenuShareAppMessage({
            title: shareTitle,
            desc: shareDesc,
            link: shareLink,
            imgUrl: shareImg,
            trigger: function (res) {
                //alert('用户点击发送给朋友');
            },
            success: function (res) {
                //alert('已分享');
            },
            cancel: function (res) {
                //alert('已取消');
            },
            fail: function (res) {
                //alert(JSON.stringify(res));
            }
        });
    }
    //注册获取“分享到朋友圈”状态事件
    function onMenuShareTimeline() {
        wx.onMenuShareTimeline({
            title: shareTitle,
            link: shareLink,
            imgUrl: shareImg,
            trigger: function (res) {
                //alert('用户点击分享到朋友圈');
            },
            success: function (res) {
                //alert('已分享');
            },
            cancel: function (res) {
                //alert('已取消');
            },
            fail: function (res) {
                //alert(JSON.stringify(res));
            }
        });
    }
    //注册获取“分享到 QQ”状态事件
    function onMenuShareQQ() {
        wx.onMenuShareQQ({
            title: shareTitle,
            desc: shareDesc,
            link: shareLink,
            imgUrl: shareImg,
            trigger: function (res) {
                //alert('用户点击分享到QQ');
            },
            complete: function (res) {
                //alert(JSON.stringify(res));
            },
            success: function (res) {
                //alert('已分享');
            },
            cancel: function (res) {
                //alert('已取消');
            },
            fail: function (res) {
                alert(JSON.stringify(res));
            }
        });
    }
    //注册获取“分享到微博”状态事件
    function onMenuShareWeibo() {
        wx.onMenuShareWeibo({
            title: shareTitle,
            desc: shareDesc,
            link: shareLink,
            imgUrl: shareImg,
            trigger: function (res) {
                //alert('用户点击分享到微博');
            },
            complete: function (res) {
                //alert(JSON.stringify(res));
            },
            success: function (res) {
                //alert('已分享');
            },
            cancel: function (res) {
                //alert('已取消');
            },
            fail: function (res) {
                //alert(JSON.stringify(res));
            }
        });
    }
    iniWx();
</script>
</body>
</html>
